package com.servlets.user;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.core.GlobalConstants;
import com.core.protocols.IServiceLayerDelegate;
import com.servicelayer.user.UserListLayer;
import com.servlets.TaskTrackerServlet;

/**
 * Servlet implementation class UserDelete
 */
public class UserDelete
        extends TaskTrackerServlet
        implements IServiceLayerDelegate {

    private static final long   serialVersionUID = 1L;

    private HttpServletResponse postResponse     = null;



    /**
     * @see HttpServlet#HttpServlet()
     */
    public UserDelete() {

        super();

    }



    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet ( HttpServletRequest request,
                           HttpServletResponse response )
            throws ServletException, IOException {

    }



    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost ( HttpServletRequest request,
                            HttpServletResponse response )
            throws ServletException, IOException {

        this.postResponse = response;

        String userId = request.getParameter(GlobalConstants.SERVLET_PARAM_KEY);

        UserListLayer userListLayer = new UserListLayer();
        userListLayer.setLayerDelegate(this);
        userListLayer.deleteObject(userId);
    }



    @Override
    public <T> void responseResponseItemsList ( final List <T> items,
                                                final Object request,
                                                final Exception exception ) {

        if ( postResponse == null ) {
            return;
        }

        if ( exception != null ) {

        }

        String redirection = null;
        redirection = String.format("%s", GlobalConstants.SERVLET_PROJECTLIST);

        try {
            postResponse.sendRedirect(redirection);
        } catch ( IOException e ) {
            e.printStackTrace();
        }

    }

}
